package com.spider.capsulation;

public class Student {
    //合理隐藏：使用private合理隐藏成员变量
    private String name;
    private int age;
    private double chinese;
    private double math;

    //构造器
//    public Student(String name,int age,double chinese,double math) {
//        this.name = name;
//        this.age = age;
//        this.chinese = chinese;
//        this.math = math;
//    }
//    public Student(){
//    }

    //合理暴露：使用public合理暴露成员变量，给成员变量赋值
    public void setName(String name) {
        this.name = name;
    }
    public void setAge(int age){
        if (age>=0&&age<=200)
            this.age = age;
        else
            System.out.println("输入的年龄有误");
    }
    public void setChinese(double chinese) {
        if (chinese>=0&&chinese<=100)
            this.chinese = chinese;
        else
            System.out.println("输入的分数有误");
    }
    public void setMath(double math) {
        if (math>=0&&math<=100)
            this.math = math;
        else
            System.out.println("输入的分数有误");
    }
    public String getName() {
        return this.name;
    }
    public void getSum()//定义一个方法求学生的总成绩
    {
        System.out.println(this.name+"的总成绩是："+(chinese+math));
    }
    public void getAvg()//定义一个方法求学生的平均成绩
    {
        System.out.println(this.name+"的平均成绩是："+(chinese+math)/2);
    }

}
